package com.fast.config;

import cn.hippo4j.config.springboot.starter.refresher.AbstractConfigThreadPoolDynamicRefresh;
import com.shuwen.ops.shaman.configmap.Config;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ConfigmapRefreshHandler extends AbstractConfigThreadPoolDynamicRefresh {

    private final static String CONFIG_NAME = "dynamicpool.yml";
    private String data = null;

    @Override
    public String getProperties() {
        return Config.getData(CONFIG_NAME);
    }

    @Override
    public void afterPropertiesSet() {
        Config.addListener(CONFIG_NAME, last -> {
            if (data == null) {
                data = last;
            } else if (!data.equals(last)) {
                dynamicRefresh(last);
            } else {
                log.warn("DynamicThreadPoolRefreshHandler is loading can not refresh!");
            }
        });
    }
}
